package com.yun.many.auth.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yun.many.auth.model.req.MenuEditReq;
import com.yun.many.auth.model.req.MenuQueryReq;
import com.yun.many.auth.model.req.UserEditReq;
import com.yun.many.auth.model.req.UserQueryReq;
import com.yun.many.auth.model.resp.MenuVo;
import com.yun.many.auth.model.resp.UserVo;
import com.yun.many.auth.service.IMenuService;
import com.yun.many.spec.vo.HttpResult;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.awt.*;

@RestController
@RequestMapping("menu")
@RequiredArgsConstructor
public class MenuController extends BaseController {

    private final IMenuService menuService;

    @PostMapping("/page")
    public HttpResult<Page<MenuVo>> pageList(MenuQueryReq req) {
        Page<MenuVo> userPage = menuService.pageMenu(req);
        return HttpResult.success(userPage);
    }

    @PostMapping("/save")
    public HttpResult<Boolean> add(@Validated MenuEditReq req, BindingResult result) {
        validate(result);

        return HttpResult.success(menuService.save(req));
    }

    @PostMapping("/delete")
    public HttpResult<Boolean> delete(MenuQueryReq req) {
        return HttpResult.success(menuService.delete(req));
    }
}
